#include "flow.h"

#include <arpa/inet.h>

Flow::Flow(u_int32_t saddr, u_int16_t source, u_int32_t daddr, u_int16_t dest)
{
    this->saddr  = saddr;
    this->source = source;

    this->daddr  = daddr;
    this->dest   = dest;

    _syn_ack = false;
    _ack = false;

    bytes = 0;
}

bool Flow::operator == (const Flow f)
{
    return ( (saddr  == f.saddr ) and
             (source == f.source) and
             (daddr  == f.daddr ) and
             (dest   == f.dest  ) )
    or
           ( (saddr  == f.daddr ) and
             (source == f.dest  ) and
             (daddr  == f.saddr ) and
             (dest   == f.source) );
}

//u_int32_t Flow::getSourceAddress()
//{
//    return saddr;
//}

u_int16_t Flow::getSourcePort()
{
    return source;
}

//u_int32_t Flow::getDestinationAddress()
//{
//    return daddr;
//}

u_int16_t Flow::getDestinationPort()
{
    return dest;
}

std::string Flow::getSourceAddress()
{
    struct in_addr inaddr;
    inaddr.s_addr = saddr;

    return std::string(inet_ntoa(inaddr));
}

std::string Flow::getDestinationAddress()
{
    struct in_addr inaddr;
    inaddr.s_addr = daddr;

    return std::string(inet_ntoa(inaddr));
}

long Flow::getBytes()
{
    return bytes;
}

void Flow::increaseBytes(long bytes)
{
    this->bytes += bytes;
}

std::string Flow::toStdString()
{
    return std::string();
}
